#include <stdio.h>
#include <string.h>

int d[ 27 ][ 6 ];

int pow( char a, int b )
{
    a = a - 'A' + 1;
    if ( d[ a ][ b ] != 0 )
        return d[ a ][ b ];
    int i;
    d[ a ][ 1 ] = a;
    for ( i = 2; i <= b; i++ )
        d[ a ][ i ] = d[ a ][ i - 1 ] * a;
    return d[ a ][ b ];
}

int main( )
{
    char data[ 13 ], result[ 6 ], tmp[ 6 ];
    int v, w, x, y, z, i, target, sum, len;
    for ( v = 0; v < 27; v++ )
        for ( w = 0; w < 6; w++ )
            d[ v ][ w ] = 0;
    while ( scanf("%d%s", &target, data) != EOF )
    {
        bool so = false;
        int max = -1;
        if ( target == 0 && strcmp( data, "END" ) == 0 )
            break;
        result[ 0 ] = '\0';
        len = strlen( data );
        for ( w = 0; w < len; w++ )
            for ( x = 0; x < len; x++ )
            {
                if ( x == w ) continue;
                for ( y = 0; y < len; y++ )
                {
                    if ( y == x || y == w ) continue;
                    for ( z = 0; z < len; z++ )
                    {
                        if ( z == x || z == w || z == y ) continue;
                        v = target + pow( data[ w ], 2 ) - pow( data[ x ], 3 ) + pow( data[ y ], 4 ) - pow( data[ z ], 5 );
                        if ( v >= 1 && v <= 26 )
                        {
                            for ( i = 0; i < len; i++ )
                            {
                                if ( data[ i ] -'A' + 1 != v || i == w || i == x || i == y || i == z ) continue;
                                break;
                            }
                            if ( i < len )
                            {
                                so = true;
                                tmp[ 0 ] = data[ i ];
                                tmp[ 1 ] = data[ w ];
                                tmp[ 2 ] = data[ x ];
                                tmp[ 3 ] = data[ y ];
                                tmp[ 4 ] = data[ z ];
                                tmp[ 5 ] = '\0';
                                if ( strcmp( tmp, result ) > 0 )
                                    strcpy( result, tmp );
                            }
                        }
                    }
                }
            }
        if ( so )
            printf("%s\n", result);
        else
            printf("no solution\n");
    }
    return 0;
}
